<?php

class PaymentController extends My_Controller_Action {

    public function mockAction() {
        try {
        $this->layout->setLayout('payment_mock');
        $this->view->amount = $amount = $this->_getParam('amount');
        $this->view->paymentId = $paymentId = $this->_getParam('payment_id');
        if (!$this->_request->isPost()) {
            return;
        }
        $status = $this->_getParam('status');
        $db = Zend_Db_Table::getDefaultAdapter();
        $db->insert('bank', array(
            'payment_id' => $paymentId,
            'amount' => $amount,
            'status' => $status,
        ));
        $this->_redirect('/payment/back-ok');
        } catch (Exception $ex) {
            d($ex);
        }
    }
    
    public function backOkAction() {
        $daoPayment = new Application_Model_DAO_Payment();
        $daoPayment->checkPayments();
        $this->addSuccess($this->translate('XXX_PAYMENT_IN_PROGRESS'));
        $this->_redirect('/');
    }

    public function checkPaymentsAction() {
        $daoPayment = new Application_Model_DAO_Payment();
        $daoPayment->checkPayments();
        d('koniec');
    }

    public function payAction() {
        $this->setContentTitle(_('XXX_PAYMENT_PAY_TITLE'));
        $code = $this->_getParam('id');
        $daoPayment = new Application_Model_DAO_Payment();
        $payment = $daoPayment->getByCode($code);
        if (empty($payment) || !in_array($payment['status'], array(Application_Model_DAO_Payment::STATUS_NEW, Application_Model_DAO_Payment::STATUS_PENDING))) {
            $this->addError($this->translate('XXX_PAYMENT_NOT_EXISTS'));
            $this->_redirect('/');
        }
        $sourceName = $payment['source_name'];
        switch ($sourceName) {
            case 'offer':
                $this->view->info = 'Opłata za umieszczenie w portalu ogłoszenia płatnego';
                break;
            case 'catalog':
                $this->view->info = 'Opłata za umieszczenie w portalu płatnego wpisu do katalogu firm i instytucji';
                break;
            case 'adv':
                $this->view->info = 'Opłata za umieszczenie w portalu reklamy';
                break;
        }
        $this->view->payment = $payment;
    }

}

